package com.avcdata.aoscustommade.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.NavigationView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.avcdata.aoscustommade.R;
import com.avcdata.aoscustommade.activity.ChangePhoneOrEmail_Activity;
import com.avcdata.aoscustommade.activity.ForgetFindOrChangePassword_Activity;
import com.avcdata.aoscustommade.activity.Login_Activity;
import com.avcdata.aoscustommade.utils.AvcConstants;
import com.avcdata.aoscustommade.utils.SharedPreferencesUtils;
import com.avcdata.aoscustommade.utils.TextUitl;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.mxn.soul.flowingdrawer_core.MenuFragment;

import it.sephiroth.android.library.picasso.Picasso;

/**
 * * 滑动菜单
 */
public class SlideMenuFragment extends MenuFragment implements View.OnClickListener {
    private ImageView ivMenuUserProfilePhoto;
    @ViewInject(R.id.personal_phone)
    private TextView personal_phone;
    @ViewInject(R.id.update_pwd)
    private LinearLayout update_pwd;
    @ViewInject(R.id.update_phone)
    private LinearLayout update_phone;

    @ViewInject(R.id.exit)
    private TextView exit;

    private SharedPreferencesUtils sp;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        sp = new SharedPreferencesUtils(getActivity());
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_menu, container,
                false);
        NavigationView mNavigationView = (NavigationView) view.findViewById(R.id.vNavigation);
        TextView change_type = (TextView) view.findViewById(R.id.change_type);
        TextView personal_phone = (TextView) view.findViewById(R.id.personal_phone);

        personal_phone.setText(sp.getUserAccount());

        if (TextUitl.isPhone(sp.getUserAccount())){
            change_type.setText("修改手机号");
        }else {
            change_type.setText("修改邮箱号");
        }

        ivMenuUserProfilePhoto = (ImageView) mNavigationView.getHeaderView(0).findViewById(R.id.ivMenuUserProfilePhoto);
        ViewUtils.inject(this, view);
        update_phone.setOnClickListener(this);
        update_pwd.setOnClickListener(this);
        exit.setOnClickListener(this);
//        personal_phone.setText ( mySharedHelper.getInstance ().getUserName () );
        setupHeader();
        return setupReveal(view);
    }

    private void setupHeader() {
        int avatarSize = getResources().getDimensionPixelSize(R.dimen.activity_vertical_margin);
        String profilePhoto = getResources().getString(R.string.app_name);
        Picasso.with(getActivity())
                .load(profilePhoto)
                .placeholder(R.drawable.background_blue)
                .resize(avatarSize, avatarSize)
                .centerCrop()
                .into(ivMenuUserProfilePhoto);
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.update_pwd:
                Intent intent1 = new Intent(getActivity(), ForgetFindOrChangePassword_Activity.class);
                intent1.putExtra(AvcConstants.PASSWORDCHANGE, "");
                startActivity(intent1);

                break;
            case R.id.update_phone:
                Intent intent = new Intent(getActivity(), ChangePhoneOrEmail_Activity.class);
                startActivity(intent);
                break;
            case R.id.exit:
                Intent intent2 = new Intent(getActivity(), Login_Activity.class);
                intent2.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent2);
                break;

        }
    }
}
